package util;


import dao.SaleDao;
import org.springframework.beans.factory.annotation.Autowired;
import pojo.Sale;

import java.util.List;

public class Page {
    /**
     * 总页数
     */
    private int totalPageCount = 0;
    /**
     * 每页现实的行数
     */
    private int pageSize = 3;
    /**
     * 总数
     */
    private int totalCount;
    private Integer dateTypeSort;
    private Integer priceSort;

    public Integer getPriceSort() {
        return priceSort;
    }

    public void setPriceSort(Integer priceSort) {
        this.priceSort = priceSort;
    }

    public Integer getDateTypeSort() {
        return dateTypeSort;
    }

    public void setDateTypeSort(Integer dateTypeSort) {
        this.dateTypeSort = dateTypeSort;
    }

    /**
     * 当前页码
     */
    private int currentPageNo = 1;
    private List<Sale> saleList;

    public List<Sale> getSaleList() {
        return saleList;
    }

    public void setSaleList(SaleDao saleDao) {
        this.saleList =
                saleDao.getSaleInfo((this.currentPageNo - 1) * this.pageSize,
                        this.pageSize, this.dateTypeSort);
    }

    public int getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalPageCount(int totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public int getCurrentPageNo() {
        return currentPageNo;
    }


    public void setTotalCount(int totalCount) {
        if (totalCount > 0) {
            this.totalCount = totalCount;
            totalPageCount = this.totalCount % pageSize == 0 ?
                    (this.totalCount / pageSize) : (this.totalCount / pageSize + 1);
        }
    }

    public void setCurrentPageNo(int currentPageNo) {
        if (currentPageNo > this.totalPageCount) {
            this.currentPageNo = 1;
        } else if (currentPageNo < 1) {
            this.currentPageNo = 1;
        } else {
            this.currentPageNo = currentPageNo;
        }
    }
}
